package com.shuangti.webdemo.controller;


import com.shuangti.webdemo.po.Emp;
import com.shuangti.webdemo.po.Result;
import com.shuangti.webdemo.servvice.EmpService;
import com.shuangti.webdemo.vo.LoginInfo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@RequiredArgsConstructor
public class LoginController {
    private final EmpService empService;
    /**
     * 登录接口
     * 用户登录成功·返回用户信息
     */

    @PostMapping("/login")
    public Result login(@RequestBody Emp emp){
        log.info("用户登录页：{}",emp);
        if (emp.getUserName().isEmpty()){
            return Result.error("请输入用户名");
        }
        if (emp.getPassword().isEmpty()){
            return Result.error("请输入密码");
        }
        LoginInfo loginInfo = empService.log(emp);

        if (loginInfo != null){

            return Result.success(loginInfo);
        }

    return Result.error("用户名或密码错误");
    }
}
